use eframe::egui;

mod menus;
mod setfont;
fn main() -> eframe::Result {
    //let options = eframe::NativeOptions::default();
    let options = eframe::NativeOptions {
        viewport: egui::ViewportBuilder::default()
            .with_inner_size([400.0, 300.0])
            .with_min_inner_size([300.0, 220.0])
            .with_icon(
                // NOTE: Adding an icon is optional
                eframe::icon_data::from_png_bytes(&include_bytes!("../icons/icon.png")[..])
                    .expect("Failed to load icon"),
            ),
        ..Default::default()
    };
    eframe::run_native(
        "第一个窗口",
        options,
        Box::new(|cc| {
            //添加image loader
            egui_extras::install_image_loaders(&cc.egui_ctx);
            Ok(Box::new(MyEguiApp::new(cc)))
        }),
    )
}
#[derive(Default)]
struct MyEguiApp {
    value: f32,
}
impl MyEguiApp {
    fn new(cc: &eframe::CreationContext<'_>) -> Self {
        // Disable feathering as it causes artifacts
        let context = &cc.egui_ctx;

        context.tessellation_options_mut(|tess_options| {
            tess_options.feathering = false;
        });
        println!(
            "{} {} {:?}",
            context.pixels_per_point(),
            context.zoom_factor(),
            context.native_pixels_per_point()
        );
        setfont::setup_custom_fonts(&cc.egui_ctx);
        Self { value: 1.0 }
    }
}
impl eframe::App for MyEguiApp {
    fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
        ctx.set_pixels_per_point(self.value);

        egui::CentralPanel::default().show(ctx, |ui| {
            // The central panel the region left after adding TopPanel's and SidePanel's
            // 获取鼠标的绝对坐标
            if let Some(pos) = ctx.input(|i| i.pointer.hover_pos()) {
                // 在窗口中显示坐标（保留一位小数）
                ui.label(format!("X: {:.1}, Y: {:.1}", pos.x, pos.y));
                println!(
                    "{} {} {:?}",
                    ctx.pixels_per_point(),
                    ctx.zoom_factor(),
                    ctx.native_pixels_per_point()
                );
            }

            ui.add(egui::Slider::new(&mut self.value, 1.0..=10.0).text("value"));
            if ui.button("Increment").clicked() {
                self.value += 1.0;
            }
        });
    }
}
